#include "pch.h"
#include "Random.h"
#include <time.h>

namespace
{
   static bool rand_init_ = false;
}

dxroids::Random::Random()
{
   if (!rand_init_)
   {
      srand(static_cast<unsigned int>(time(nullptr)));
      rand_init_ = true;
   }
}

int32_t dxroids::Random::Next(int32_t _min_value, int32_t _max_value) const
{
   double const factor = static_cast<double>(rand()) / (RAND_MAX + 1);
   double const range = (_max_value - _min_value);
   double const result = range * factor + _min_value;
   return static_cast<int32_t>(result);
}

float dxroids::Random::NextFloat(float _min_value, float _max_value) const
{
   double const factor = static_cast<double>(rand()) / (RAND_MAX + 1);
   double const range = (_max_value - _min_value);
   double const result = range * factor + _min_value;   
   return static_cast<float>(result);
}